<?php
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/jquery.validity/jquery.validate.js",CClientScript::POS_END);
?>
<div>
    <div class="form-horizontal userform">
    <?php 
        $form=$this->beginWidget('CActiveForm', array(
            'id'=>'information-form',
            'enableAjaxValidation'=>false,
            "htmlOptions"=>array("enctype"=>"multipart/form-data"),
        ));
    ?>
    <?php echo $form->errorSummary($model); ?>
        <fieldset>
            <table class="table table-bordered">
                <tbody>
                    <tr>
                        <td>
                            <div class="control-group">
                                <label class="control-label" for="p_gid">产品类型</label>
                                <div class="controls">
                                    <?php echo $form->dropDownList($model,'p_gid',Category::model()->getCategory(),$htmlOptions=array ('name'=>"p_gid",'empty'=>'请选择产品类型','class'=>"pull-left")); ?>
									<p class="error  pull-left pl8">不能为空！</p>
                                    <p for="p_gid" class="error" style=""><?=isset($model->errors['p_gid'])?join('',$model->errors['p_gid']):""?></p>
								</div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="p_name">标题 <span class="rcolor">*</span></label>
                                <div class="controls">
                                    <?php
                                        echo $form->textField($model,'p_name',array('class'=>'input-large pull-left','maxlength'=>160,'name'=>'p_name'));
                                    ?>
                                    <p class="error  pull-left pl8">不能为空！</p>
                                    <p for="p_name" class="error" style=""><?=isset($model->errors['p_name'])?join('',$model->errors['p_name']):""?></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="i_title">产品内容 <span class="rcolor">*</span></label>
                                <div class="controls">
                                   <?php $this->widget('ext.ckeditor.CKEditorWidget',array(
								  "model"=>$model,                 # Data-Model
								  "attribute"=>'p_produce',          # Attribute in the Data-Model
								  "defaultValue"=>$model->p_produce,     # Optional

								  # Additional Parameter (Check http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html)
								  "config" => array(
									  "height"=>"600px",
									  "width"=>"1002px",
									  "toolbar"=>"Full",
									  ),

								  #Optional address settings if you did not copy ckeditor on application root
								  "ckEditor"=>Yii::app()->basePath."/../ckeditor/ckeditor.php",
																  # Path to ckeditor.php
								  "ckBasePath"=>Yii::app()->baseUrl."/ckeditor/",
																  # Realtive Path to the Editor (from Web-Root)
								  ) ); ?>
                                    <p class="error  pull-left pl8">不能为空！</p>
                                    <p for="p_produce" class="error" style=""><?=isset($model->errors['p_produce'])?join('',$model->errors['p_produce']):""?></p>
                                </div>
                            </div>
                            
                            <div class="form-actions">
                                <button type="submit" class="btn btn-primary" name="addsubmit" value="add"  ><?=!$model->isNewRecord?"修改":"添加"?></button> &nbsp;
                                <?php
                                    if(isset($_GET['return'])&&$_GET['return']=='index'){
                                        $url = Yii::app()->createUrl("admin/product/index",array("id"=>$model->p_id));
                                    }else{
                                        $url = isset($_COOKIE['ggnewslistreturnurl'])?$_COOKIE['ggnewslistreturnurl']:Yii::app()->createUrl("admin/product/index");
                                    }
                                ?>
                                <a href="<?=$url?>" class="btn btn-primary">返回</a>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </fieldset>
        <?php $this->endWidget(); ?>
    </div>
</div>
<script>
    $(document).ready(function(){
	$("#information-form").validate({
            autoCreateRanges:true	,
            errorClass: "error",
            errorElement: "p",
            rules: {
                p_gid: {
                    required: true,
                },
                p_name: {
                    required: true,
                    maxlength:500,
                },
                p_produce: {
                    required: true,
                },
            },
            
            messages: {
                p_gid:{
                    required: '请选择产品类型',
                },
                p_name:{
                    required: '请输入标题内容',
                    maxlength:'不得超过500字',
                },
                p_produce:{
                    required: '请输入标题内容',
                },
            },
        });
    })
</script> 

